﻿using System.Runtime.InteropServices;
using UnityEngine;

namespace Car.NavMesh
{
    public enum CarPartitionType
    {
        watershed,
        monotone,
        layers,
    };


    [StructLayout(LayoutKind.Sequential)]
    [System.Serializable]
    public class CarBuildConfig
    {
        /// The width of the field along the x-axis. [Limit: >= 0] [Units: vx]
        public int width;

        /// The height of the field along the z-axis. [Limit: >= 0] [Units: vx]
        public int height;

        /// The width/height size of tile's on the xz-plane. [Limit: >= 0] [Units: vx]
        public int tileSize;

        /// The size of the non-navigable border around the heightfield. [Limit: >=0] [Units: vx]
        public int borderSize;

        /// The xz-plane cell size to use for fields. [Limit: > 0] [Units: wu] 
        public float cs = 0.3f;

        /// The y-axis cell size to use for fields. [Limit: > 0] [Units: wu]
        public float ch = 0.2f;

        /// The minimum bounds of the field's AABB. [(x, y, z)] [Units: wu]
        public Vector3 bmin;

        /// The maximum bounds of the field's AABB. [(x, y, z)] [Units: wu]
        public Vector3 bmax;

        /// The maximum slope that is considered walkable. [Limits: 0 <= value < 90] [Units: Degrees] 
        public float walkableSlopeAngle = 45.0f;

        /// Minimum floor to 'ceiling' height that will still allow the floor area to 
        /// be considered walkable. [Limit: >= 3] [Units: vx] 
        public int walkableHeight = 10;

        /// Maximum ledge height that is considered to still be traversable. [Limit: >=0] [Units: vx] 
        public int walkableClimb = 4;

        /// The distance to erode/shrink the walkable area of the heightfield away from 
        /// obstructions.  [Limit: >=0] [Units: vx] 
        public int walkableRadius = 2;

        /// The maximum allowed length for contour edges along the border of the mesh. [Limit: >=0] [Units: vx] 
        public int maxEdgeLen = 12;

        /// The maximum distance a simplfied contour's border edges should deviate 
        /// the original raw contour. [Limit: >=0] [Units: vx]
        public float maxSimplificationError = 1.2f;

        /// The minimum number of cells allowed to form isolated island areas. [Limit: >=0] [Units: vx] 
        public int minRegionArea = 8;

        /// Any regions with a span count smaller than this value will, if possible, 
        /// be merged with larger regions. [Limit: >=0] [Units: vx] 
        public int mergeRegionArea = 20;

        /// The maximum number of vertices allowed for polygons generated during the 
        /// contour to polygon conversion process. [Limit: >= 3] 
        public int maxVertsPerPoly = 6;

        /// Sets the sampling distance to use when generating the detail mesh.
        /// (For height detail only.) [Limits: 0 or >= 0.9] [Units: wu] 
        public float detailSampleDist = 6.0f;

        /// The maximum distance the detail mesh surface should deviate from heightfield
        /// data. (For height detail only.) [Limit: >=0] [Units: wu] 
        public float detailSampleMaxError = 1.0f;

        public float agentHeight = 2.0f;
        public float agentRadius = 0.6f;
        public float agentMaxClimb = 0.9f;
        public float agentMaxSlope = 45.0f;
        public int partitionType = (int)CarPartitionType.watershed;
    }
}
